var id = RequestURLParam.getParam("id"),
    type = RequestURLParam.getParam("type"),
    moduleId = RequestURLParam.getParam("moduleId"),
    moduleName = decodeURIComponent(RequestURLParam.getParam("moduleName")),
    urlTxt;

var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

var $
    ,form
    ,layer;

$(document).ready(function() {
    layui.use(['jquery', 'form', 'layer'], function(){
        $ = layui.jquery
            , form = layui.form
            , layer = layui.layer;

        if(type === "add"){
            urlTxt = "/wf/form/plugins/add";

            var uuid = UUID.prototype.createUUID().toLowerCase();
            $("#id").val(uuid);
            $("#moduleId").val(moduleId);
            $("#moduleName").val(moduleName);
        }else{
            urlTxt = "/wf/form/plugins/update";
            loadData(id);
        }

        submit();  //监听事件
    });
});

function loadData(id) {
    ActHttpRequest("/wf/form/plugins/findVOById",{"id":id},function (data) {
        if(data.wfFormPluginsVO != null){
            var formPlugins = data.wfFormPluginsVO;

            $("#fpId").val(formPlugins.fpId);
            $("#moduleId").val(formPlugins.moduleId);
            $("#moduleName").val(formPlugins.moduleName);
            $("#name").val(formPlugins.name);
            $("#nameCn").val(formPlugins.nameCn);
            $("#pluginsState").val(formPlugins.pluginsState);
        }
    },'post',false);
}

function submit() {
    form.on("submit(save)",function (data){
        var param = data.field;

        ActHttpRequest(urlTxt, param, function (data) {
            if(data.OK=="OK"){
                parent.layer.msg("保存成功！",{icon:1,time : 800});
                parent.layer.close(index);
            }else{
                layer.alert(data.message);
            }
        },'post',false);
        return false;
    });
}

/*
function init_data(){
    ActHttpRequest("formPlugin!findById.do?id="+fid,{},function(data){
        if(data.OK=="OK"){
            if(data.formPlugin){
                $("#form1 .formPlugin").each(function(){
                    mini.get(this.id).setValue(data.formPlugin[this.id]);
                });
                /!*************添加非mini组件的初始化或mini中value/Text等组合组件的初始化 start*************************!/


                /!*************添加非mini组件的初始化或mini中value/Text等组合组件的初始化 end*************************!/

            }
        }else{
            mini.alert(data.message);
        }
    },null,'加载中。。。');
}
function saveData(){
    if(!minForm.validate())
        return;
    setTimeout(function(){

        if (!minForm.isValid()) {
            mini.alert("验证失败，点击页面红色叹号查看！");
            return;
        }
        var formData=$("#form1").serializeJSON();
        ActHttpRequest(urlTxt,formData,function(data){
            if(data.OK=="OK"){
                window.CloseOwnerWindow("OK");
            }else{
                mini.alert(data.message);
            }
        }, null, null, null, '保存中。。。', true);
    },500);
}*/
